﻿namespace WinForms
{
    using Bll.Systems;
    using Model.Systems;
    using PublicStaticClass;
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Web.Security;
    using System.Windows.Forms;
    using WinForms.ControlList.Chain;
    using WinForms.ControlList.Comm;
    using WinForms.ControlList.Company;
    using WinForms.ControlList.Finance;
    using WinForms.ControlList.Guest;
    using WinForms.ControlList.LeadFrom;
    using WinForms.ControlList.Popedom;
    using WinForms.ControlList.Processing;
    using WinForms.ControlList.Procurement;
    using WinForms.ControlList.Sales;
    using WinForms.ControlList.Stock;
    using WinForms.ControlList.Supplier;
    using WinForms.ControlList.Systems;
    using WinForms.ControlList.User;
    using WinForms.Properties;
    using WinFormSession;

    public class FrmMains : Form
    {
        private Panel AllPanel;
        private IContainer components = null;
        private ConfigEnt config = null;
        private string currMenuName = "";
        public bool dhStatic = false;
        private FrmLogin frmLogin = null;
        private Form frmWindow = null;
        protected ArrayList hash = new ArrayList();
        public static string KeyPath;
        private Label lbl_BanQuan;
        private Label lbl_HuanYing;
        private Label lbl_Times;
        private Label lblDeptName;
        private FrmLead lead = null;
        private LinkLabel link_AlertPassWord;
        private LinkLabel link_BeginPag;
        private LinkLabel linkLabel1;
        private MenuStrip menuStrips;
        private Panel pan_bottom;
        private Panel pan_KjButton;
        private Panel Pan_Main;
        private Panel pan_Menu;
        private Panel pan_Topright;
        private Panel pan_User;
        private Panel pan_XiTongYingWen;
        private Panel panel_Times;
        private Panel panel2;
        private PictureBox pictureBox1;
        private PictureBox pictureBox2;
        private Timer timer_ShowTime;

        public FrmMains()
        {
            ////貌似这里是加密狗
            //this.CheckKeyDll();
            this.InitializeComponent();
            base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            base.SetStyle(ControlStyles.UserPaint, true);
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.RegisterDeviceNotification();
        }

        public void BuildNewFrame(string menuName)
        {
            bool flag = false;
            if (this.frmWindow != null)
            {
                this.frmWindow.Dispose();
                this.frmWindow = null;
            }

            switch (menuName)
            {
                case "起始页":
                    flag = true;
                    this.frmWindow = new FrmStartup();
                    this.currMenuName = menuName;
                    break;
                case "连锁店管理":
                    flag = true;
                    this.frmWindow = new FrmChainList();
                    this.currMenuName = menuName;
                    break;
                case "供应商管理":
                    flag = true;
                    this.frmWindow = new FrmSupplierList();
                    this.currMenuName = menuName;
                    break;
                case "客户资料管理":
                    flag = true;
                    this.frmWindow = new FrmGuestList();
                    this.currMenuName = menuName;
                    break;
                case "客户折扣类型管理":
                    flag = true;
                    this.frmWindow = new FrmGuestGradeList();
                    this.currMenuName = menuName;
                    break;
                case "仓库管理":
                    flag = true;
                    this.frmWindow = new FrmDigitallibraryList();
                    this.currMenuName = menuName;
                    break;
                case "商品管理":
                    flag = true;
                    this.frmWindow = new FrmCommList();
                    this.currMenuName = menuName;
                    break;
                case "商品类别管理":
                    flag = true;
                    this.frmWindow = new FrmCommTypeList();
                    this.currMenuName = menuName;
                    break;
                case "帐户管理":
                    flag = true;
                    this.frmWindow = new FrmCompayAccountList();
                    this.currMenuName = menuName;
                    break;
                case "账务收支管理":
                    flag = true;
                    this.frmWindow = new FrmCompayAccountDetailsList();
                    this.currMenuName = menuName;
                    break;
                case "管理库存":
                    flag = true;
                    this.frmWindow = new FrmStockList();
                    this.currMenuName = menuName;
                    break;
                case "新增库存":
                    flag = true;
                    new FrmStockAdd().ShowDialog();
                    break;
                case "管理采购":
                    flag = true;
                    this.frmWindow = new FrmProcurementList();
                    this.currMenuName = menuName;
                    break;
                case "开具采购单":
                    flag = true;
                    new FrmProcurementAdd().ShowDialog();
                    break;
                case "采购付款管理":
                    flag = true;
                    this.frmWindow = new FrmProcurementPaymentList();
                    this.currMenuName = menuName;
                    break;
                case "入库单据查询及打印":
                    flag = true;
                    this.frmWindow = new FrmProcurementPrintAndVeiwList();
                    this.currMenuName = menuName;
                    break;
                case "试泡管理":
                    flag = true;
                    this.frmWindow = new FrmTestDunkList();
                    this.currMenuName = menuName;
                    break;
                case "新增茶叶试泡":
                    flag = true;
                    new FrmTestDunkAdd().ShowDialog();
                    break;
                case "开具销售单":
                    flag = true;
                    new FrmOrdersAdd().ShowDialog();
                    break;
                case "销售管理":
                    flag = true;
                    this.frmWindow = new FrmOrdersList();
                    this.currMenuName = menuName;
                    break;
                case "销售收款管理":
                    flag = true;
                    this.frmWindow = new FrmOrderPaymentList();
                    this.currMenuName = menuName;
                    break;
                case "销售单据查询及打印":
                    flag = true;
                    this.frmWindow = new FrmOrdersSelectAndPrint();
                    this.currMenuName = menuName;
                    break;
                case "员工管理":
                    flag = true;
                    this.frmWindow = new FrmUserList();
                    this.currMenuName = menuName;
                    break;
                case "角色管理":
                    flag = true;
                    this.frmWindow = new FrmRoleList();
                    this.currMenuName = menuName;
                    break;
                case "备份数据":
                    flag = true;
                    new FrmBackupAndResumeDb().ShowDialog();
                    break;
                case "部门管理":
                    flag = true;
                    this.frmWindow = new FrmDeptList();
                    this.currMenuName = menuName;
                    break;
                case "销售报表统计":
                    flag = true;
                    this.frmWindow = new FrmSalesStatList();
                    this.currMenuName = menuName;
                    break;
                case "采购报表统计":
                    flag = true;
                    this.frmWindow = new FrmProcurementStatList();
                    this.currMenuName = menuName;
                    break;
                case "进销存明细账":
                    flag = true;
                    this.frmWindow = new FrmInvoicingList();
                    this.currMenuName = menuName;
                    break;
                case "利润统计":
                    flag = true;
                    new FrmGainStatList().Show();
                    break;
                case "访问我们网站":
                    try
                    {
                        MessageBox.Show("域名还没申请");
                        //Process.Start("IEXPLORE.EXE", "http://www.teaxt.com");
                    }
                    catch (Exception)
                    {
                    }
                    break;
                case "关于":
                    flag = true;
                    new FrmAbout().ShowDialog();
                    break;
                case "软件自动升级":
                    this.OperUpdateCode();
                    break;
                case "系统设置":
                    flag = true;
                    new FrmSystemsSet().ShowDialog();
                    break;
                case "使用帮助":
                    this.OpenHelp();
                    break;
                case "帮助管理":
                    flag = true;
                    this.frmWindow = new FrmhelpsList();
                    this.currMenuName = menuName;
                    break;
                case "茶叶拼堆":
                    flag = true;
                    this.frmWindow = new FrmTeaMixedList();
                    this.currMenuName = menuName;
                    break;
                case "茶叶包装":
                    flag = true;
                    this.frmWindow = new FrmTeaPackagingList();
                    this.currMenuName = menuName;
                    break;
                case "茶叶挑枝":
                    flag = true;
                    this.frmWindow = new FrmTeaProcessingList();
                    this.currMenuName = menuName;
                    break;
                case "查看操作日志":
                    flag = true;
                    this.frmWindow = new FrmWorkLogList();
                    this.currMenuName = menuName;
                    break;

                default:
                    break;
            }


            if (flag && (this.frmWindow != null))
            {
                this.Pan_Main.Controls.Clear();
                Size size = new Size(this.Pan_Main.Size.Width, this.Pan_Main.Size.Height);
                this.frmWindow.Size = size;
                this.frmWindow.TopLevel = false;
                this.frmWindow.Show();
                this.Pan_Main.Controls.Add(this.frmWindow);
            }
        }

        private bool CheckIsIntial()
        {
            string str = ConfigurationManager.AppSettings["IsInitializations"];
            if (str == "0")
            {
                return false;
            }
            return true;
        }

        private bool CheckIsOneUse(string menuName)
        {
            if (this.config.IsUseMeUse == 1)
            {
                if (menuName == "角色管理")
                {
                    return false;
                }
                if (menuName == "员工管理")
                {
                    return false;
                }
                if (menuName == "部门管理")
                {
                    return false;
                }
            }
            if ((this.config.IsUseProc == 0) && (menuName == "采购管理"))
            {
                return false;
            }
            if ((this.config.IsUseSale == 0) && (menuName == "销售管理"))
            {
                return false;
            }
            if ((this.config.IsUseStock == 0) && (menuName == "库存管理"))
            {
                return false;
            }
            if (this.config.IsUseTeaDunk == 0)
            {
                if (menuName == "试泡管理")
                {
                    return false;
                }
                if (menuName == "新增茶叶试泡")
                {
                    return false;
                }
            }
            return true;
        }

        private bool checkJionMenu(string MenuId)
        {
            UserEnt loginUser = PublicAppliction.LoginUser;
            if (this.config.IsUseMeUse == 1)
            {
                return true;
            }
            if (this.hash != null)
            {
                foreach (object obj2 in this.hash)
                {
                    menulue menulue = (menulue)obj2;
                    if (menulue.MenuId == MenuId)
                    {
                        return (menulue.IsUseMenu == "1");
                    }
                }
            }
            return false;
        }

        private void CheckKeyDll()
        {
            try
            {
                string path = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString() + "/2";
                bool flag = File.Exists(path);
                string str2 = Environment.GetFolderPath(Environment.SpecialFolder.System) + "/SYUNEW3D.dll";
                if (!File.Exists(str2))
                {
                    File.Copy(path, str2);
                }
                if (!flag)
                {
                    MessageBox.Show("程序出现异常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    base.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("程序出现异常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                base.Close();
            }
        }

        private bool CheckOtherMenu(string menuName)
        {
            return ((menuName == "帮助") || ((menuName == "使用帮助") || ((menuName == "关于") || ((menuName == "访问我们网站") || (menuName == "软件自动升级")))));
        }

        private bool CheckReg()
        {
            switch (this.CheckRegInfo())
            {
                case 4:
                    MessageBox.Show("您的加密狗与使用软件版本不符,如有疑问请与我们客服!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return false;

                case 3:
                    MessageBox.Show("未找到加密狗,请插入加密狗后,再次开启程序!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return false;

                case 2:
                    MessageBox.Show("您的连锁店程序已经到期,请您续费后继续使用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return false;

                case 1:
                    MessageBox.Show("您的连锁店程序即将到期,请您尽快续费,以免影响使用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return true;
            }
            return true;
        }

        private int CheckRegInfo()
        {
            Exception exception;
            try
            {
                string source = this.getKeyInfo();
                if (source == "")
                {
                    return 3;
                }
                Rijndael rijndael = new Rijndael("kkkkkejiosjadafkjiefj@!#!@#!@3");
                string[] strArray = rijndael.Decrypt(source).Split(new char[] { '|' });
                if (strArray.Length > 0)
                {
                    DateTime time = DateTime.Parse(strArray[2]);
                    DateTime time2 = DateTime.Parse(strArray[3]);
                    try
                    {
                        string str3 = strArray[4];
                        if ((str3 != "1") && (str3 != "99"))
                        {
                            return 4;
                        }
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        return 4;
                    }
                    int num = DateTime.Compare(time, DateTime.Now);
                    int num2 = DateTime.Compare(DateTime.Now, time2);
                    if ((num < 0) && (num2 < 0))
                    {
                        if (DateTime.Compare(DateTime.Now.AddDays(7.0), time2) < 0)
                        {
                            return 0;
                        }
                        return 1;
                    }
                }
                else
                {
                    return 2;
                }
                return 2;
            }
            catch (Exception exception2)
            {
                exception = exception2;
                return 2;
            }
        }

        private void contextMenuStrip_ItemClick(object sender, EventArgs e)
        {
            ToolStripItem item = (ToolStripItem)sender;
            this.BuildNewFrame(item.Text);
        }

        private void DataCatchLoad()
        {
            PublicAppliction.ReloadCommTypeDtCatch();
            PublicAppliction.ReloadDlDtCatch();
            PublicAppliction.ReloadParDtCatch();
            PublicAppliction.ReloadGuestGradeCatch();
            PublicAppliction.ReloadCompanyAccountCatch();
            PublicAppliction.ReloadUserDt();
            PublicAppliction.ReloadSupplierCatch();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FCopy()
        {
            string str4 = FormsAuthentication.HashPasswordForStoringInConfigFile(GetMachineInfo.GetCpuInfo() + GetMachineInfo.GetMoAddress(), "MD5");
            string str5 = ConfigurationManager.AppSettings["machineInfos"];
            if (str4 != str5)
            {
                MessageBox.Show("机器码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                base.Close();
            }
        }

        [DllImport("SYUNEW3D.dll")]
        public static extern int FindPort(int start, StringBuilder OutKeyPath);
        [DllImport("SYUNEW3D.dll")]
        public static extern int FindPort_2(int start, int in_data, int verf_data, StringBuilder OutKeyPath);
        private void FrmMains_Activated(object sender, EventArgs e)
        {
            HotKey.RegisterHotKey(base.Handle, 100, HotKey.KeyModifiers.None, Keys.F2);
        }

        private void FrmMains_Leave(object sender, EventArgs e)
        {
            HotKey.UnregisterHotKey(base.Handle, 100);
        }

        private void FrmMains_SizeChanged(object sender, EventArgs e)
        {
            this.lbl_BanQuan.Location = new Point((this.pan_bottom.Width - this.lbl_BanQuan.Width) / 2, this.lbl_BanQuan.Location.Y);
        }

        private string getKeyInfo()
        {
            StringBuilder outKeyPath = new StringBuilder("", 0x100);
            if (FindPort(0, outKeyPath) != 0)
            {
                return "";
            }
            KeyPath = outKeyPath.ToString();
            byte[] outData = new byte[1];
            int num = YReadEx(outData, 0, 1, "FFFFFFFF", "FFFFFFFF", KeyPath);
            short capacity = outData[0];
            StringBuilder outstring = new StringBuilder("", capacity);
            for (int i = 0; i < capacity; i++)
            {
                outstring.Append(0);
            }
            YReadString(outstring, 1, capacity, "FFFFFFFF", "FFFFFFFF", KeyPath);
            return outstring.ToString();
        }

        [DllImport("SYUNEW3D.dll")]
        public static extern int GetLen(string InString);
        private void GetLoginUser()
        {
            string str = PublicAppliction.LoginUser.RoleId.ToString();
            if (str != "")
            {
                DataTable list = MenuLinkRoleBll.GetList("RoleId=" + str);
                if (list.Rows.Count > 0)
                {
                    string[] strArray = list.Rows[0]["MenuLinkValue"].ToString().Split(new char[] { '|' });
                    int length = 0;
                    foreach (string str3 in strArray)
                    {
                        menulue menulue = new menulue();
                        if (str3 != "")
                        {
                            Exception exception;
                            string str4 = str3;
                            try
                            {
                                length = str3.IndexOf("$");
                                menulue.MenuId = str4.Substring(0, length);
                                str4 = str4.Remove(0, length + 2);
                            }
                            catch (Exception exception1)
                            {
                                exception = exception1;
                            }
                            try
                            {
                                length = str4.IndexOf(")");
                                menulue.IsUseMenu = str4.Substring(0, length);
                            }
                            catch (Exception exception2)
                            {
                                exception = exception2;
                            }
                            this.hash.Add(menulue);
                        }
                    }
                }
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager resources = new ComponentResourceManager(typeof(FrmMains));
            this.AllPanel = new Panel();
            this.Pan_Main = new Panel();
            this.pan_bottom = new Panel();
            this.lbl_BanQuan = new Label();
            this.pan_Menu = new Panel();
            this.menuStrips = new MenuStrip();
            this.pan_User = new Panel();
            this.pan_KjButton = new Panel();
            this.link_BeginPag = new LinkLabel();
            this.link_AlertPassWord = new LinkLabel();
            this.linkLabel1 = new LinkLabel();
            this.panel_Times = new Panel();
            this.lbl_Times = new Label();
            this.lblDeptName = new Label();
            this.lbl_HuanYing = new Label();
            this.pictureBox2 = new PictureBox();
            this.panel2 = new Panel();
            this.pan_XiTongYingWen = new Panel();
            this.pictureBox1 = new PictureBox();
            this.pan_Topright = new Panel();
            this.timer_ShowTime = new Timer(this.components);
            this.AllPanel.SuspendLayout();
            this.pan_bottom.SuspendLayout();
            this.pan_Menu.SuspendLayout();
            this.pan_User.SuspendLayout();
            this.pan_KjButton.SuspendLayout();
            this.panel_Times.SuspendLayout();
            ((ISupportInitialize)this.pictureBox2).BeginInit();
            this.panel2.SuspendLayout();
            ((ISupportInitialize)this.pictureBox1).BeginInit();
            base.SuspendLayout();
            this.AllPanel.BackgroundImage = Resources.login_bg;
            this.AllPanel.Controls.Add(this.Pan_Main);
            this.AllPanel.Controls.Add(this.pan_bottom);
            this.AllPanel.Controls.Add(this.pan_Menu);
            this.AllPanel.Controls.Add(this.pan_User);
            this.AllPanel.Controls.Add(this.panel2);
            this.AllPanel.Dock = DockStyle.Fill;
            this.AllPanel.Location = new Point(0, 0);
            this.AllPanel.Name = "AllPanel";
            this.AllPanel.Size = new Size(0x381, 0x1c4);
            this.AllPanel.TabIndex = 2;
            this.Pan_Main.Dock = DockStyle.Fill;
            this.Pan_Main.Location = new Point(0, 0x77);
            this.Pan_Main.Name = "Pan_Main";
            this.Pan_Main.Size = new Size(0x381, 0x128);
            this.Pan_Main.TabIndex = 8;
            this.pan_bottom.BackgroundImage = Resources.bottom_bg;
            this.pan_bottom.Controls.Add(this.lbl_BanQuan);
            this.pan_bottom.Dock = DockStyle.Bottom;
            this.pan_bottom.Location = new Point(0, 0x19f);
            this.pan_bottom.Name = "pan_bottom";
            this.pan_bottom.Size = new Size(0x381, 0x25);
            this.pan_bottom.TabIndex = 7;
            this.lbl_BanQuan.AutoSize = true;
            this.lbl_BanQuan.BackColor = Color.FromArgb(0, 0, 15, 0xff);
            this.lbl_BanQuan.Location = new Point(0x164, 12);
            this.lbl_BanQuan.Name = "lbl_BanQuan";
            this.lbl_BanQuan.Size = new Size(0xb9, 12);
            this.lbl_BanQuan.TabIndex = 0;
            this.lbl_BanQuan.Text = "磐嘉软件 版权所有(C) 2009-2012";
            this.pan_Menu.Controls.Add(this.menuStrips);
            this.pan_Menu.Dock = DockStyle.Top;
            this.pan_Menu.Location = new Point(0, 0x54);
            this.pan_Menu.Name = "pan_Menu";
            this.pan_Menu.Size = new Size(0x381, 0x23);
            this.pan_Menu.TabIndex = 6;
            this.menuStrips.BackgroundImage = Resources.menu_bg;
            this.menuStrips.Dock = DockStyle.Fill;
            this.menuStrips.Font = new Font("宋体", 10f);
            this.menuStrips.Location = new Point(0, 0);
            this.menuStrips.Name = "menuStrips";
            this.menuStrips.RenderMode = ToolStripRenderMode.System;
            this.menuStrips.Size = new Size(0x381, 0x23);
            this.menuStrips.TabIndex = 0;
            this.menuStrips.Text = "menuStrip";
            this.pan_User.BackColor = Color.FromArgb(0, 0, 15, 0xff);
            this.pan_User.BackgroundImage = Resources.user_bg;
            this.pan_User.Controls.Add(this.pan_KjButton);
            this.pan_User.Controls.Add(this.panel_Times);
            this.pan_User.Controls.Add(this.lblDeptName);
            this.pan_User.Controls.Add(this.lbl_HuanYing);
            this.pan_User.Controls.Add(this.pictureBox2);
            this.pan_User.Dock = DockStyle.Top;
            this.pan_User.Location = new Point(0, 0x37);
            this.pan_User.Name = "pan_User";
            this.pan_User.Size = new Size(0x381, 0x1d);
            this.pan_User.TabIndex = 5;
            this.pan_KjButton.Controls.Add(this.link_BeginPag);
            this.pan_KjButton.Controls.Add(this.link_AlertPassWord);
            this.pan_KjButton.Controls.Add(this.linkLabel1);
            this.pan_KjButton.Dock = DockStyle.Right;
            this.pan_KjButton.Location = new Point(0x1c5, 0);
            this.pan_KjButton.Name = "pan_KjButton";
            this.pan_KjButton.Size = new Size(0xf4, 0x1d);
            this.pan_KjButton.TabIndex = 11;
            this.link_BeginPag.AutoSize = true;
            this.link_BeginPag.LinkBehavior = LinkBehavior.HoverUnderline;
            this.link_BeginPag.LinkColor = Color.White;
            this.link_BeginPag.Location = new Point(0x31, 8);
            this.link_BeginPag.Name = "link_BeginPag";
            this.link_BeginPag.Size = new Size(0x41, 12);
            this.link_BeginPag.TabIndex = 15;
            this.link_BeginPag.TabStop = true;
            this.link_BeginPag.Text = "返回工作区";
            this.link_BeginPag.LinkClicked += new LinkLabelLinkClickedEventHandler(this.link_BeginPag_LinkClicked);
            this.link_AlertPassWord.AutoSize = true;
            this.link_AlertPassWord.LinkBehavior = LinkBehavior.HoverUnderline;
            this.link_AlertPassWord.LinkColor = Color.White;
            this.link_AlertPassWord.Location = new Point(0x79, 8);
            this.link_AlertPassWord.Name = "link_AlertPassWord";
            this.link_AlertPassWord.Size = new Size(0x35, 12);
            this.link_AlertPassWord.TabIndex = 14;
            this.link_AlertPassWord.TabStop = true;
            this.link_AlertPassWord.Text = "更改密码";
            this.link_AlertPassWord.LinkClicked += new LinkLabelLinkClickedEventHandler(this.link_AlertPassWord_LinkClicked);
            this.linkLabel1.AutoSize = true;
            this.linkLabel1.LinkBehavior = LinkBehavior.HoverUnderline;
            this.linkLabel1.LinkColor = Color.White;
            this.linkLabel1.Location = new Point(0xb5, 8);
            this.linkLabel1.Name = "linkLabel1";
            this.linkLabel1.Size = new Size(0x35, 12);
            this.linkLabel1.TabIndex = 13;
            this.linkLabel1.TabStop = true;
            this.linkLabel1.Text = "退出程序";
            this.linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
            this.panel_Times.Controls.Add(this.lbl_Times);
            this.panel_Times.Dock = DockStyle.Right;
            this.panel_Times.Location = new Point(0x2b9, 0);
            this.panel_Times.Name = "panel_Times";
            this.panel_Times.Size = new Size(200, 0x1d);
            this.panel_Times.TabIndex = 10;
            this.lbl_Times.AutoSize = true;
            this.lbl_Times.ForeColor = SystemColors.ActiveCaptionText;
            this.lbl_Times.Location = new Point(0x12, 9);
            this.lbl_Times.Name = "lbl_Times";
            this.lbl_Times.Size = new Size(0x1d, 12);
            this.lbl_Times.TabIndex = 0;
            this.lbl_Times.Text = "时间";
            this.lblDeptName.AutoSize = true;
            this.lblDeptName.ForeColor = Color.White;
            this.lblDeptName.Location = new Point(0x42, 9);
            this.lblDeptName.Name = "lblDeptName";
            this.lblDeptName.Size = new Size(0, 12);
            this.lblDeptName.TabIndex = 9;
            this.lbl_HuanYing.AutoSize = true;
            this.lbl_HuanYing.ForeColor = SystemColors.ActiveCaptionText;
            this.lbl_HuanYing.Location = new Point(13, 9);
            this.lbl_HuanYing.Name = "lbl_HuanYing";
            this.lbl_HuanYing.Size = new Size(0x1d, 12);
            this.lbl_HuanYing.TabIndex = 8;
            this.lbl_HuanYing.Text = "欢迎";
            this.pictureBox2.Image = Resources.ico01;
            this.pictureBox2.Location = new Point(0x2d, 7);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new Size(14, 15);
            this.pictureBox2.TabIndex = 7;
            this.pictureBox2.TabStop = false;
            this.panel2.BackColor = Color.FromArgb(0xe3, 0xf7, 0xf6);
            this.panel2.BackgroundImage = Resources.logobgto;
            this.panel2.Controls.Add(this.pan_XiTongYingWen);
            this.panel2.Controls.Add(this.pictureBox1);
            this.panel2.Controls.Add(this.pan_Topright);
            this.panel2.Dock = DockStyle.Top;
            this.panel2.Location = new Point(0, 0);
            this.panel2.Name = "panel2";
            this.panel2.Size = new Size(0x381, 0x37);
            this.panel2.TabIndex = 4;
            this.pan_XiTongYingWen.BackgroundImage = Resources.logo_2;
            this.pan_XiTongYingWen.Location = new Point(15, 0x2b);
            this.pan_XiTongYingWen.Name = "pan_XiTongYingWen";
            this.pan_XiTongYingWen.Size = new Size(0x153, 8);
            this.pan_XiTongYingWen.TabIndex = 4;
            this.pictureBox1.BackgroundImage = Resources.logo_12;
            this.pictureBox1.Location = new Point(15, 4);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Size(0x112, 0x23);
            this.pictureBox1.TabIndex = 3;
            this.pictureBox1.TabStop = false;
            this.pan_Topright.BackgroundImage = Resources.top_bg;
            this.pan_Topright.Dock = DockStyle.Right;
            this.pan_Topright.Location = new Point(0x199, 0);
            this.pan_Topright.Name = "pan_Topright";
            this.pan_Topright.Size = new Size(0x1e8, 0x37);
            this.pan_Topright.TabIndex = 2;
            this.timer_ShowTime.Enabled = true;
            this.timer_ShowTime.Interval = 0x3e8;
            this.timer_ShowTime.Tick += new EventHandler(this.timer_ShowTime_Tick);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.AutoSize = true;
            base.ClientSize = new Size(0x381, 0x1c4);
            base.Controls.Add(this.AllPanel);
            this.DoubleBuffered = true;
            base.Icon = (Icon)resources.GetObject("$this.Icon");
            base.Name = "FrmMains";
            this.Text = "茶叶进销存管理系统(标准版)";
            base.WindowState = FormWindowState.Maximized;
            base.Load += new EventHandler(this.Mains_Load);
            base.SizeChanged += new EventHandler(this.FrmMains_SizeChanged);
            base.Activated += new EventHandler(this.FrmMains_Activated);
            base.Leave += new EventHandler(this.FrmMains_Leave);
            this.AllPanel.ResumeLayout(false);
            this.pan_bottom.ResumeLayout(false);
            this.pan_bottom.PerformLayout();
            this.pan_Menu.ResumeLayout(false);
            this.pan_Menu.PerformLayout();
            this.pan_User.ResumeLayout(false);
            this.pan_User.PerformLayout();
            this.pan_KjButton.ResumeLayout(false);
            this.pan_KjButton.PerformLayout();
            this.panel_Times.ResumeLayout(false);
            this.panel_Times.PerformLayout();
            ((ISupportInitialize)this.pictureBox2).EndInit();
            this.panel2.ResumeLayout(false);
            ((ISupportInitialize)this.pictureBox1).EndInit();
            base.ResumeLayout(false);
        }

        private void LastChildToolStripMenuItem_PaintTwo(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.FromArgb(0x9c, 0xdd, 0x75), 1, ButtonBorderStyle.Solid, Color.FromArgb(0x9c, 0xdd, 0x75), 1, ButtonBorderStyle.Solid, Color.FromArgb(0x9c, 0xdd, 0x75), 1, ButtonBorderStyle.Solid, Color.FromArgb(0x9c, 0xdd, 0x75), 1, ButtonBorderStyle.Solid);
        }

        private void LastToolStripMenuItem_MouseMove(object sender, MouseEventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            item.BackgroundImage = Resources.menu_bg1;
        }

        private void LastToolStripMenuItem_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.FromArgb(0, 0, 15, 0xff), 1, ButtonBorderStyle.Solid, Color.FromArgb(0, 0, 15, 0xff), 1, ButtonBorderStyle.Solid, Color.FromArgb(0, 0, 15, 0xff), 1, ButtonBorderStyle.Solid, Color.FromArgb(0, 0, 15, 0xff), 1, ButtonBorderStyle.Solid);
        }

        private void link_AlertPassWord_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FrmAlterPassWord word = new FrmAlterPassWord();
            if (word.ShowDialog() == DialogResult.OK)
            {
                Application.Restart();
            }
        }

        private void link_BeginPag_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.BuildNewFrame("起始页");
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            base.Close();
        }

        private void LoadChildMenu(DataTable MenuTable, string TreeId, ToolStripMenuItem items)
        {
            UserEnt loginUser = PublicAppliction.LoginUser;
            string filterExpression = "";
            if (loginUser.IsSuperManage == 1)
            {
                filterExpression = " MenuSId='" + TreeId + "' and IsSuperMenu=1 and ISFMenu=0";
            }
            else
            {
                filterExpression = " MenuSId='" + TreeId + "' and IsSuperMenu=0 and ISFMenu=0";
            }
            DataRow[] rowArray = MenuTable.Select(filterExpression, "MenuTaxisNum");
            foreach (DataRow row in rowArray)
            {
                if ((this.checkJionMenu(row["MenuId"].ToString()) && this.CheckIsOneUse(row["MenuName"].ToString())) || this.CheckOtherMenu(row["MenuName"].ToString()))
                {
                    ToolStripMenuItem item = new ToolStripMenuItem
                    {
                        ToolTipText = row["MenuName"].ToString(),
                        Name = row["MenuId"].ToString(),
                        Text = row["MenuName"].ToString()
                    };
                    item.Click += new EventHandler(this.contextMenuStrip_ItemClick);
                    items.DropDownItems.Add(item);
                }
            }
        }

        [DllImport("kernel32.dll")]
        public static extern int lstrlenA(string InString);
        private void Mains_Load(object sender, EventArgs e)
        {
            base.Hide();
            this.lbl_BanQuan.Location = new Point((this.pan_bottom.Width - this.lbl_BanQuan.Width) / 2, this.lbl_BanQuan.Location.Y);

            //// 加密判断
            //if (!this.CheckReg())
            //{
            //    base.Close();
            //}
            //else 
            if (!this.CheckIsIntial())
            {
                FrmSInitSystems systems = new FrmSInitSystems();
                if (systems.ShowDialog() == DialogResult.OK)
                {
                    Application.Restart();
                }
                else
                {
                    base.Close();
                }
            }
            else
            {
                this.config = ConfigBll.GetModel(1);
                if (this.config == null)
                {
                    Application.Exit();
                }
                else
                {
                    UserEnt loginUser;
                    if (this.config.IsUseMeUse == 0)
                    {
                        this.frmLogin = new FrmLogin();
                        this.frmLogin.Activate();
                        if (this.frmLogin.ShowDialog() == DialogResult.Cancel)
                        {
                            base.Close();
                        }
                        else
                        {
                            this.DataCatchLoad();
                            base.Show();
                            base.WindowState = FormWindowState.Maximized;
                            this.GetLoginUser();
                            this.Menu_Load();
                            loginUser = PublicAppliction.LoginUser;
                        }
                    }
                    else
                    {
                        loginUser = UserBll.GetModel(int.Parse(UserBll.GetList("UserName='管理员'").Rows[0]["userid"].ToString()));
                        PublicAppliction.LoginUser = loginUser;
                        WinformSession.GetSession()["user"] = loginUser;
                        this.DataCatchLoad();
                        base.Show();
                        base.WindowState = FormWindowState.Maximized;
                        this.Menu_Load();
                        this.link_AlertPassWord.Visible = false;
                    }
                    this.BuildNewFrame("起始页");
                    if (this.config.IsUseDaoHang == 1)
                    {
                        this.lead = new FrmLead(this);
                        this.lead.Show();
                        this.dhStatic = true;
                    }
                    DeptEnt model = DeptBll.GetModel(PublicAppliction.LoginUser.DeptId);
                    if (model != null)
                    {
                        this.lblDeptName.Text = this.lblDeptName.Text + "  " + model.DeptName;
                    }
                    this.lblDeptName.Text = this.lblDeptName.Text + "  " + PublicAppliction.LoginUser.UserName;
                    PublicAppliction.frmMain = this;
                    PublicAppliction.configEnt = this.config;
                }
            }
        }

        private void Menu_Load()
        {
            this.menuStrips.Visible = false;
            UserEnt loginUser = PublicAppliction.LoginUser;
            DataTable list = MenuListBll.GetList("");
            string filterExpression = "ISFMenu=1";
            DataRow[] rowArray = list.Select(filterExpression, "MenuTaxisNum");
            foreach (DataRow row in rowArray)
            {
                if ((this.checkJionMenu(row["MenuId"].ToString()) && this.CheckIsOneUse(row["MenuName"].ToString())) || this.CheckOtherMenu(row["MenuName"].ToString()))
                {
                    ToolStripMenuItem items = new ToolStripMenuItem
                    {
                        ToolTipText = row["MenuName"].ToString(),
                        Name = row["MenuId"].ToString(),
                        Text = row["MenuName"].ToString(),
                        BackColor = Color.FromArgb(0, 0, 4, 0x44)
                    };
                    items.Paint += new PaintEventHandler(this.LastToolStripMenuItem_Paint);
                    items.MouseMove += new MouseEventHandler(this.LastToolStripMenuItem_MouseMove);
                    this.LoadChildMenu(list, row["MenuId"].ToString(), items);
                    this.menuStrips.Items.Add(items);
                }
            }
            this.menuStrips.Visible = true;
        }

        public void OnDeviceChange(ref Message msg)
        {
            int wParam = (int)msg.WParam;
            if (wParam == 0x8004)
            {
                Win32.DEV_BROADCAST_DEVICEINTERFACE1 dev_broadcast_deviceinterface = (Win32.DEV_BROADCAST_DEVICEINTERFACE1)Marshal.PtrToStructure(msg.LParam, typeof(Win32.DEV_BROADCAST_DEVICEINTERFACE1));
                base.Close();
            }
        }

        private void OpenHelp()
        {
            MessageBox.Show("还未制作帮助文档");
            //Process process = new Process {
            //    StartInfo = { FileName = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "//help.chm" }
            //};
            //process.Start();
            //if (process.HasExited)
            //{
            //    process.Kill();
            //}
        }

        private void OperUpdateCode()
        {
            string aProPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\AutoUpdateForms.exe";
            this.StartProcess(aProPath);
        }

        private void RegisterDeviceNotification()
        {
            Win32.DEV_BROADCAST_DEVICEINTERFACE structure = new Win32.DEV_BROADCAST_DEVICEINTERFACE();
            int cb = Marshal.SizeOf(structure);
            structure.dbcc_size = cb;
            structure.dbcc_devicetype = 5;
            structure.dbcc_reserved = 0;
            structure.dbcc_classguid = Win32.GUID_DEVINTERFACE_USB_DEVICE;
            structure.dbcc_name = 0;
            IntPtr ptr = Marshal.AllocHGlobal(cb);
            Marshal.StructureToPtr(structure, ptr, true);
            if (Win32.RegisterDeviceNotification(base.Handle, ptr, 0) == IntPtr.Zero)
            {
                MessageBox.Show(Win32.GetLastError().ToString());
            }
        }

        public bool StartProcess(string aProPath)
        {
            try
            {
                Process process = Process.Start(aProPath);
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        private void timer_ShowTime_Tick(object sender, EventArgs e)
        {
            this.lbl_Times.Text = "当前时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x219:
                    this.OnDeviceChange(ref m);
                    break;

                case 0x312:
                    if ((m.WParam.ToInt32() == 100) && (this.config.IsUseDaoHang == 1))
                    {
                        if (this.dhStatic)
                        {
                            this.lead.Hide();
                            this.dhStatic = false;
                        }
                        else
                        {
                            this.lead.Show();
                            this.dhStatic = true;
                        }
                    }
                    break;
            }
            base.WndProc(ref m);
        }

        [DllImport("SYUNEW3D.dll")]
        public static extern int YReadEx(byte[] OutData, short Address, short mylen, string HKey, string LKey, string KeyPath);
        [DllImport("SYUNEW3D.dll")]
        public static extern int YReadString(StringBuilder outstring, short Address, short mylen, string HKey, string LKey, string KeyPath);
        [DllImport("SYUNEW3D.dll")]
        public static extern int YWriteEx(byte[] InData, short Address, short mylen, string HKey, string LKey, string KeyPath);
        [DllImport("SYUNEW3D.dll")]
        public static extern int YWriteString(string InString, short Address, string HKey, string LKey, string KeyPath);

        private delegate void CrossThreadOperationControl();
    }
}

